import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const routes = [
    {
      path: '/',
      name: 'login',
      component: () => import('./components/Login.vue')
    },    
	{
	  path: '/home',
	  name: 'Home',
	  redirect:'/console/index',
	  component: () => import('./views/Home.vue'),
	  children:[
		  {
		    path: '/console/index',
		    name: 'Console',
		    component: () => import('./components/console/Index.vue')
		  },
		  {
		    path: '/menu/index',
		    name: 'Menu',
		    component: () => import('./components/menu/Index.vue')
		  },
		  {
			  path: '/admin/index',
			  name: 'Admin',
			  component: () => import('./components/admin/Index.vue')
		  },
		  {
			  path:'/role/index',
			  name:'Role',
			  component: () => import('./components/role/Index.vue')
		  },
		  {
			  path:'/config/basics',
			  name:'Basics',
			  component: () => import('./components/config/Basics.vue')
		  },
		  {
			  path:'/config/deniedip',
			  name:'Deniedip',
			  component: () => import('./components/config/Deniedip.vue')			  
		  },
		  {
			  path:'/config/upload',
			  name:'Upload',
			  component: () => import('./components/config/Upload.vue')			  
		  }
		  
	  ]
	}  
	
  ]


const router = new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

//导航守卫验证是否存在token
router.beforeEach((to,from,next) => {
	if(to.path == '/'){
		next();
	}else{
		const token = window.sessionStorage.getItem('token');
		if(!token){
			next('/');
		}else{
			next();
		}
	}
})

export default router